#include <iostream>
#include "Xps/Tasks/Task.h"
#include "Xps/Manager/Manager.h"
#include "Xps/Object/ObjectFactory.h"
#include "Xps/Message/ACKMessage.h"
#include "Xps/Message/PingMessage.h"
#include "Xps/Packet/DataPacket.h"

namespace Xps
{
    Task::Task(const std::string &_Name)
        :name(_Name)
    {
    }

    Task::~Task(void)
    {
    }

    const std::string & Task::getName() const
    {
        return name;
    }

    bool Task::IsSubscribedToProtocol( const std::string &_ProtocolName )
    {
        return true;
    }

    void Task::Perform( const std::string &_ProtocolName, const IObject *_Object )
    {

        switch(_Object->getType())
        {
            case PING_MESSAGE:
                {
                    IObject::Ptr object(new ACKMessage((const PingMessage *)_Object));
                    IPacket::Ptr packet(new DataPacket());
                    packet->setPayload(object);
                    Manager::getInstance()->PushPacket(_ProtocolName,packet);

                    break;
                }
            case ACK_MESSAGE:
                {
                    float k= ((const ACKMessage *)_Object)->getTimeElapsed();
                    int w=0;
                    break;
                }
            default:
                {
                    break;
                }
        }

    }
};